Data changes rarely arrive alone: a transfer must debit one account and credit another, and an order must reserve stock and record a payment. If the system stops halfway through, the database is left describing a world that never existed. A transaction is the database's answer to that problem — a sequence of one or more operations that the database treats as a single, indivisible unit of work.
All of it, or none of it
Inside a transaction, every operation belongs to one outcome. The database never exposes a finished state in which only part of the transaction happened. The classic illustration is a transfer between two bank accounts: reduce the balance of the source account, then increase the balance of the destination account. If only the first step succeeded, money would vanish; if only the second, money would appear from nowhere. Wrapping both steps in one transaction removes both possibilities.
This all-or-nothing guarantee is called atomicity. Commit is the act that makes the transaction's changes permanent; a transaction that never commits leaves no trace at all. Durability adds the final piece: once a commit has returned, the change survives even if the machine loses power a moment later.
A transaction is a boundary
It helps to picture a transaction as a boundary drawn around a group of statements. Before the boundary and after it, the data satisfies the rules the structure imposes. Inside the boundary, intermediate states exist — one account is already debited while the other is not yet credited — but those states are private to the transaction. Later statements in other sessions do not treat them as the truth.
Two jobs at once
Transactions therefore do two jobs. The first is failure handling: if the process crashes, the connection drops, or a statement raises an error, the database can restore the state that existed before the transaction began. The second is visibility control: while the work is in progress, other readers are shielded from the unfinished result. These two jobs are related but not identical — atomicity decides whether changes are kept, while visibility is governed by isolation, the setting that controls how much concurrent transactions may see of each other.
